<?php

/***************************************************************************

           TPLN  by HAYOUN Laurent

           website: http://tpln.sourceforge.net
           email: php_work@hotmail.com

****************************************************************************/

class TPLN_Debug
{
// debugage
 var $struct_mode = 0;
 var $struct_tab; // contient le tableau entier

/**
<docgeny>
<submenu name="FileStructMode" parent="functions">
 <name lang="fr">FileStructMode</name>
 <name lang="en">FileStructMode</name>

 <description lang="fr">
 Pour afficher la structure d'un fichier template vous devez utilser la fonction FileStructMode() avant la fonction Open()
 </description>

 <description lang="en">
 This function permits to print the structure of your file opened with function Open().
 </description>

 <example>
 include("../../TPLN/TPLN.php");

 $TPLN = new TPLN;
 $TPLN->FileStructMode(); // view the skeleton of template

 $TPLN->Open("multiple_loop_bloc.html");
 $TPLN->Write();
 </example>

 <see>Open</see>
</submenu>
</docgeny>
**/

function FileStructMode()
{
 $this->struct_mode = 1;
}

function TraceMode()
{
 $this->trace_mode = 1;
}

 /*****************  Parent function ******/
function _StructOpen()
{
 if($this->struct_mode == 0){return;}

  $this->_StructFile();
  $this->_StructItems();
  $this->_StructBlocs();
  $this->_Arr2HtmlTab();
}


function _StructFile()
{
  $this->struct_tab[] = "<b>File:</b> {".$this->f[$this->f_no]["name"]."}<br>\n";
}


function _StructItems()
 {
 $p_var = array("_UrlBng",
                "_UrlPrev",
                "_UrlNext",
                "_UrlEnd",
                "_UrlPageNav",
                "_PageNumber",
                "_PageCount",
                "_First",
                "_Last",
                "_Count",
                "_NavColor",
                "_Chrono",
                "_Logo",
                "_Version",
                "_Field");

  $tab = "<b>Variable(s) found:</b> ".count($this->f[$this->f_no]["items"])."<br>\n";

 $cur_item = array(); // initiamisation
 $tpln_var = array(); // initialisation

   if(count($this->f[$this->f_no]["items"]) > 0)
   {

     $item_tmp = array_unique($this->f[$this->f_no]["items"]);
     foreach($item_tmp as $name)
       {
         if(!in_array($name, $p_var))
            {
              $cur_item[] = $name;
            }
          else
            {
              $tpln_var[] = $name;
           }
       }
   }

   $tab .= $this->_Arr2List("Php variable(s)",$this->f[$this->f_no]["php_items"],'{$',"}");
   $tab .= $this->_Arr2List("User variable(s)",$cur_item,"{","}");
   $tab .= $this->_Arr2List("Private variable(s)",$tpln_var,"{","}");
   $tab .= $this->_Arr2List("Tpln Include Command(s)",$this->f[$this->f_no]["cmd_items"],"{#include(",")}");

   $this->struct_tab[] = $tab;

 }

 function _StructBlocs()
 {
   $this->struct_tab[] = $this->_Arr2List("Blocs",$this->f[$this->f_no]["shortcut_blocs"]["all"]);
 }


/************ extra functions ************/
function _Arr2List($text="",$arr,$bng="",$end="")
 {
  $txt = NULL;

  if(!empty($text))
  {$txt .= "<b>$text:</b> ".count($arr)."<br>";}

  if(count($arr) > 0)
  {
   $txt .= "<ul>";

   foreach($arr as $name)
     {
      $txt .= "<li>".$bng.$name.$end."</li>\n";

      if($text == "Blocs")
       {
            if(count($this->f[$this->f_no]["shortcut_blocs"]["$name"]["items"]) > 0)
               {
                 $txt .=  "<ul>";

                            foreach($this->f[$this->f_no]["shortcut_blocs"]["$name"]["items"] as $item)
                              {
                               $txt .= "<li>\{$item}</li>";
                              }

                 $txt .=  "</ul>";
                }

       }
     }

    $txt .= "</ul>";
  }

  return $txt;
}

function _Arr2HtmlTab()
{
  for($i=0;$i < count($this->struct_tab);$i++)
  {
   if($i == 0)
     {
      echo "<table border=1 cellspacing=0 cellpadding=3>";
     }

    echo "<tr><td>{$this->struct_tab[$i]}</td><tr>";

   if($i == count($this->struct_tab)-1)
    {
     echo "</table>";
    }

  }

}



}

?>